import {
  api,
  util,
  storage
} from '../../../js/util'
import {
  router
} from '../../../js/router';
import {
  cart
} from '../../../js/modules/order';
import {
  theme
} from '../../../js/modules/theme'
import authorize from '../../../js/modules/authorize'
import {
  detail,
  mall,
  list,
  scant
} from "../../../js/modules/mall.js";
import {
  activities,
  liveService
} from '../../../js/modules/market';
import {
  config
} from "../../../js/modules/gloab";
import {
  GoodsNumCache
} from '../../../js/modules/propertycache.js'
import {
  $ecCountDown
} from '../../../components/index.js'
const data_cache_key = 'index_template_data_'
const app = getApp()
const componentBehavior = require('../../../js/common/ComponentBehavior')

Component({
  behaviors: [componentBehavior],
  lifetimes: {
    attached() {
      this.fasterComponent = this.selectComponent("#fasterComponent");
      this.outofstock = this.selectComponent("#outofstock");
      this.stockdistribution = this.selectComponent("#stockdistribution");
      this.deliveryComponent = this.selectComponent("#deliveryComponent");
    },
    detached() {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  /**
   * 组件的属性列表
   */
  properties: {
    pageId: {
      value: 0,
      type: Number
    },
    isPreview: {
      value: false,
      type: Boolean
    },
    GoodsUnitDisplayMode: {
      value: 0,
      type: Number
    },
    mainColor: String,
    Currency: String,
    isLogin: Boolean,
    NoLoginShowPrice: Boolean,
    height: Number,
    CartName: String,
    listState: Boolean,
    FrontShowStockDetail: Boolean
  },

  /**
   * 组件的初始数据
   */
  data: {
    imgDomain: api.imgDomain,
    videoDomain: api.videoDomain,
    enableOss: api.enableOss,
    widgets: [],
    loadIndex: 0, //当前加载最后位置
    param: [], //连接服务端参数
    keywords: '', //搜索的关键字
    isScanty: false,
    quantityDigits: 0, //数量显示小数位数
    priceDigits: 2, //价格显示小数位数
    addressAssignDepot: api.addressAssignDepot, //收货地区匹配仓库
    time: null, //加载时时间缀
    loopCount: 0, //循环数量
    windowWidth: 0, //屏幕宽度
    windowHeight: 0, //屏幕高度
    spectStyle: 0,
    addr: {
      code: ""
    },
    showShareShadow: false,
    timerArray: {},
    Currency: app.globalData.Currency, //货币符号
    couponImg: '../../../assets/images/disableCoupon.png',
    CartName: '',
    autoplay: true,
    isLoading: false,
    indexPageBackground: '', // 自定义页面设置的背景色
    BGColorForMobile: '', // 网站设置中的全局背景色
  },
  /**
   * 组件的方法列表
   */
  methods: {
    initPropertity(isAlone) {
      //通用域名下才清页面挂件
      if (isAlone != true) {
        storage.remove(data_cache_key + this.data.pageId);
      }
      for (let i in this.data.timerArray) {
        clearInterval(this.data.timerArray[i]);
      }
      this.setData({
        param: [], //连接服务端参数
        keywords: '', //搜索的关键字
      });
    },
    /**
     * 加载首页装修的模板信息
     */
    loadTemplates: function () {
      let {
        pageId,
        addressAssignDepot
      } = this.data;
      let that = this;
      let entity = authorize.getEntity() || authorize.getDefault();
      this.data.h5ImgDomain = api.host.replace(/(https:\/\/www)|(https:\/\/)/, "http://m");
      this.data.windowWidth = wx.getSystemInfoSync().windowWidth;
      this.data.windowHeight = wx.getSystemInfoSync().windowHeight;
      this.setData({
        isLoading: true
      });
      theme.loadPageWidgets(pageId, entity.fkId, data_cache_key, (widgets) => {
        app.globalData.index.isReload = false;
        that.setData({
          isLoading: false,
          loadIndex: 0, //当前加载最后位置
          widgets: widgets,
          isLogin: authorize.isLogin('store')
        }, () => {
          if (api.addressAssignDepot){
            that.deliveryComponent.getDefaultAddress();
          } else {
            that.loadPageWidgets(0);
            that.onNoticeParent();
          }
        });
      });
    },
    loadMorePageWidgets() {
      let {
        loadIndex,
        widgets
      } = this.data;
      if (loadIndex < widgets.length) {
        this.loadPageWidgets(loadIndex + 1);
      }
    },
    loadPageWidgets(startIndex) {
      var that = this;
      let {
        widgets,
        windowHeight
      } = this.data;
      if (widgets.length > 0 && startIndex < widgets.length) {
        let pageHeght = 0;
        let endIndex = startIndex;
        for (let i = startIndex; i < widgets.length; i++) {
          let item = widgets[i];
          pageHeght += (item.WidgetHeight || 0);
          endIndex = i;
          //每次加载2屏的数据
          if (pageHeght > windowHeight * 2) {
            break;
          }
        }
        //判断是否已加载完
        if (startIndex <= endIndex && endIndex < widgets.length) {
          let target = [];
          for (let i = startIndex; i <= endIndex; i++) {
            const item = widgets[i];
            //排除搜索、标题和分割线这三个组件
            if (item != undefined && item.WidgetName != undefined && item.WidgetName != 'Search' && item.WidgetName != 'Title' && item.WidgetName != 'Line') {
              var key = item.Keyword + "|" + item.WidgetName;
              target.push(key);
            }
          }
          this.setData({
            loadIndex: endIndex
          }); //记录当前加载最后位置
          if (target.length > 0) {
            this.setData({
              isLoading: true
            });
            this.loadWidgetDatas(target, () => {
              // 当已加载的内容高度小于2屏时，继续加载更多数据
              that.getContentHeight().then((contentHeight) => {
                // 没有获取到高度或者已经超过2屏高度，无需继续加载
                if (contentHeight == -1 || (contentHeight > windowHeight * 2)) {
                  that.setData({isLoading: false});
                  return
                }
                // 不足两屏也加载更多数据，防止因为权限问题拿不到数据导致不能加载更多数据的问题
                that.loadMorePageWidgets()
              })
            });
          }
        }
      } else {
        this.setData({
          isLoading: false
        })
      }
    },
    /**
     * @target 请求的组件id集合
     * 多个挂件数据加载 
     */
    loadWidgetDatas(target, callback) {
      var that = this;
      var entity = authorize.getEntity();
      var param = {
        FKFlag: app.dns.proprietor,
        FKWay: app.dns.fkWay,
        UserId: entity != undefined ? entity.fkId : 0, // 登录用户Id,
        Sid: app.dns.proprietorId, //网页所有者Id,
        ProprietorId: app.dns.proprietorId,
        Widgets: target.join(','),
        AreaId: that.data.addr.code,
        token: entity ? entity.manager.Token : '',
      };
      util.post("theme.data.getpagewidgetdbdata", param, (res) => {
        var data = res.data;
        if (data.Success) {
          that.decorateWidgets(data.Content, callback);
        } else {
          if (callback && typeof (callback) == "function") {
            callback();
          };
        }
      }, '3.0', null, false);
    },
    /**
     * @wdatalist 要组装的列表
     * 组装挂件
     */
    decorateWidgets(wdatalist, callback) {
      let that = this;
      let {
        widgets,
        h5ImgDomain
      } = that.data;
      if (wdatalist != undefined && Object.keys(wdatalist).length > 0) {
        //组装数据
        for (var i = 0; i < widgets.length; i++) {
          let widget = widgets[i];
          let keyword = widget.Keyword;
          let widgetData = wdatalist[keyword];
          if (widgetData != undefined && widgetData.length > 0) {
            if (widget.WidgetName == "Content") {
              let content = widgetData[0].Content;
              let reg = /src\s*=\s*['"](\/[^'"]*?)['"]/ig;
              content = content.replace(reg, "src=\"" + h5ImgDomain + "$1\"");
              let name = `richtext_${keyword}`
              that.setData({
                [name]: content
              })
              widgetData[0].Content = content;
              widgetData[0].richtext = content
              widgetData[0].richtext_name = name
            } else if ((widget.WidgetName == "ProductsCart" || widget.WidgetName == "Products")) {
              for (let j = 0; j < widgetData.length; j++) {
                var item = widgetData[j];
                let units = item.AuxiliaryUnits;
                if (units && units.length > 0) {
                  for (let k = 0; k < units.length; k++) {
                    if ((item.DefaultUnit || item.AuxUnit) == units[k].Name) {
                      item.ZIndex = k;
                      break;
                    }
                  }
                }
                item.IsGuide = widget.IsGuide;
                //这里需要把原始值用另一个字段存下来，方便后面计算时用原始值计算
                item.SBuyLowerLimit = item.BuyLowerLimit || 0;
                item.SBuyUpperLimit = item.BuyUpperLimit || 0;
                item.SStock = item.Stock;
                if (item.IsSingle == 1) {
                  that.unitList(item.AuxiliaryUnits, item.UnitPrices, item.CartCount, item);
                }
              }
              //加载促销信息
              activities.loadProductActivities(widgetData, false, 0, that.data.addr.code, function (goodslist, index) {
                let key_activite = "widgets[" + index + "].Datas";
                for (var j = 0; j < goodslist.length; j++) {
                  goodslist[j].show = false;
                  if (goodslist[j].isPanic && goodslist[j].PanicGoods) {
                    goodslist[j].PanicGoods.map((p) => {
                      that.unitList(goodslist[j].AuxiliaryUnits, p.UnitPrices, goodslist[j].CartCount, goodslist[j])
                    })
                  } else {
                    that.unitList(goodslist[j].AuxiliaryUnits, goodslist[j].UnitPrices, goodslist[j].CartCount, goodslist[j])
                  }
                }
                //重新渲染
                that.setData({
                  [key_activite]: goodslist,
                  time: new Date().getTime()
                });
              }, i);
            } else if (widget.WidgetName == "Carousel") {
              widgetData.map((item) => {
                item.Interval = widget.ExtParameter.Interval;
              });
            } else if (widget.WidgetName == "GroupBuy" || widget.WidgetName == "PreSale") {
              widgetData = widgetData.filter((item) => item.IsShow == 1);
            }
            widget.Datas = widgetData;
          }
          widget = this.renderItemStyle(widget)
          widgets[i] = widget
        }
        that.setData({
          widgets: widgets
        }, function () {
          // 只有首页才刷新底部导航信息
          if (!that.data.pageId) {
            theme.getFootBar(widgets);
          }
          if (callback && typeof (callback) == "function") {
            callback();
          };
        });
      }
    },
    unitList(AuxiliaryUnits, UnitPrices, CartCount, goodlist) {
      let {
        quantityDigits
      } = this.data;
      for (var i = 0; i < AuxiliaryUnits.length; i++) {
        var item = AuxiliaryUnits[i];
        var t = detail.parseRule(UnitPrices, item.Translated, item.Qty || 0, false);
        if (t.has) {
          item.price = t.price;
          if (t.integral) {
            item.integral = t.integral;
          }
        }
        var otherAuxiliaryUnits = AuxiliaryUnits.filter(unit => {
          return unit.Translated != item.Translated
        });
        var otherUnitQuantity = 0;
        if (otherAuxiliaryUnits && otherAuxiliaryUnits.length > 0) {
          otherAuxiliaryUnits.map((child, idx) => {
            if (child.Qty != undefined && child.Qty > 0) {
              otherUnitQuantity += (child.Qty || 0) * (child.Translated || 1);
            }
          });
        }
        item.BuyLowerLimit = goodlist.SBuyLowerLimit > 0 && goodlist.SBuyLowerLimit > otherUnitQuantity ? util.keepDecimal("ceil", goodlist.SBuyLowerLimit - otherUnitQuantity, quantityDigits) : 0;
        item.BuyUpperLimit = goodlist.SBuyUpperLimit > 0 && goodlist.SBuyUpperLimit > otherUnitQuantity ? util.keepDecimal("ceil", goodlist.SBuyUpperLimit - otherUnitQuantity, quantityDigits) : 0;
        item.Stock = goodlist.SStock > 0 && goodlist.SStock > otherUnitQuantity ? util.keepDecimal("ceil", goodlist.SStock - otherUnitQuantity, quantityDigits) : 0;
        item.IsSingle = goodlist.IsSingle;
        item.DefaultUnit = item.Name;
        item.ZeroStockBuy = goodlist.ZeroStockBuy;
        item.SpecValue = goodlist.SpecValue;
        item.ProductId = goodlist.ProductId;
        item.DiscountId = goodlist.DiscountId;
        item.DiscountType = goodlist.DiscountType;
        AuxiliaryUnits[i] = item;
        if (this.data.GoodsUnitDisplayMode == 0 && item.Translated == (goodlist.Translated || goodlist.Radix)) {
          goodlist.BuyLowerLimit = item.BuyLowerLimit;
          goodlist.BuyUpperLimit = item.BuyUpperLimit;
          goodlist.Stock = item.Stock;
        }
      }
    },
    /**
     * 重新加载购物车插件显示数量
     */
    loadProductQuantity: function (callback) {
      var that = this;
      if (that.data.time && GoodsNumCache.compareTime(that.data.time)) {
        for (var k = 0; k < that.data.widgets.length; k++) {

          var key = that.data.widgets[k].Keyword;
          if (key.indexOf("_ProductsCart_") > -1) {
            var goodsList = that.data.widgets[k].Datas || [];
            for (var i = 0; i < goodsList.length; i++) {
              goodsList[i].CartCount = GoodsNumCache.getProductNum(goodsList[i].ProductId, goodsList[i].CartCount, goodsList[i].IsSingle == 1);
            }
            that.data.widgets[k].Datas = goodsList;
          }
        }

        that.setData({
          widgets: that.data.widgets
        });
      }
      if (callback && typeof (callback) == "function") {
        callback();
      }
    },

    /**搜索文本框的输入事件 */
    keywordsInput(e) {
      this.setData({
        keywords: e.detail.value
      });
    },
    /**
     * 搜索
     */
    search(e) {
      var that = this;
      app.globalData.product_list.index_search_keyword = that.data.keywords;
      router.navigate({
        path: "productList"
      });
      let id = `#suggestion`
      let component = this.selectComponent(id)
      component.hide()
      component.addKeyword(that.data.keywords)
      // 通过历史记录搜索时,搜索完后清楚当前keywords数据,防止下次直接点击搜索时出错
      if (e.detail.reset) {
        that.setData({
          keywords: ''
        })
      }
    },
    /**
     * input获取焦点
     * @param {*} e 
     */
    focus(e) {
      let id = `#suggestion`
      let component = this.selectComponent(id)
      component.show()
    },
    /**
     * 清空当前input内容
     */
    deleteInputKeyWords (e) {
      console.log(e)
      this.setData({
        keywords: ''
      });
    },
    /**
     * 点击 历史/推荐 中的内容搜索
     * @param {*} e 
     */
    suggestionSearch (e) {
      this.setData({
        keywords: e.detail.keyword
      })
      this.search({
        detail: {
          reset: true
        }
      })
    },
    /**
     * 扫码
     */
    onScanCodeEvent: function (e) {
      // 只允许从相机扫码
      wx.scanCode({
        success: (res) => {
          app.globalData.product_list.index_search_keyword = res.result;
          router.navigate({
            path: "productList"
          });
        }
      })
    },
    /**
     * 替换链接 
     */
    linkTo(e) {
      var url = e.currentTarget.dataset.url || e.detail.url;
      theme.linkTo(url);
    },
    wxParseTagATap(e) {
      let event = e.detail.event || {currentTarget: {dataset: {src: ''}}}
      var url = event.currentTarget.dataset.src;
      theme.linkTo(url);
    },
    /**
     * 跳转到商品详情
     */
    toDetail(e) {
      var pagetype = e.currentTarget.dataset.pagetype;
      var linkparam = e.currentTarget.dataset.linkparam;
      var loadcomplate = e.currentTarget.dataset.loadcomplate;
      if (loadcomplate != 1) return;
      var url = "productDetail";
      if (pagetype == 1 || pagetype == 2) {
        url = "groupDetail";
      }
      theme.routerTo(url, linkparam);
    },
    bindLabel(e) {
      var id = e.currentTarget.dataset.id;
      router.navigate({
        path: "promotionDetail",
        params: {
          id: id
        }
      })
    },
    /**
     * 跳转特价详情
     */
    toPanicDetail(e) {
      var idx = e.currentTarget.dataset.idx;
      var item = e.currentTarget.dataset.list[idx];
      var finish = e.currentTarget.dataset.finish;
      var ptype = 3;

      if (finish) {
        util.alert("活动已结束");
        return;
      }
      if (item.PanicStatus == -1 || item.IsStart != 1) {
        ptype = 0;
      }
      router.navigate({
        path: "productDetail",
        params: {
          ptype: ptype,
          id: item.ProductId,
          sid: item.FKId,
          discounttype: 2,
          discountid: item.Id
        }
      });

    },
    /**
     * 跳转拼团预售详情
     */
    toGroupDetail(e) {
      const id = e.currentTarget.dataset["id"];
      const productId = e.currentTarget.dataset["productid"];
      const groupStatus = e.currentTarget.dataset["groupstatus"];
      const actualover = e.currentTarget.dataset["actualover"];
      const type = e.currentTarget.dataset["type"];
      if (actualover == 1 && groupStatus == 2) {
        util.alert("商品已被抢光啦！");
        return;
      }
      if (groupStatus == 0) {
        util.alert("活动已经结束啦！");
        return;
      }
      router.navigate({
        path: "groupDetail",
        params: {
          ptype: type,
          id: id,
          productId: productId
        }
      })
    },

    /**
     * 显示多规则
     *  */
    onShowGoodsModal(e) {
      var that = this;
      e = e.detail;
      that.fasterComponent.setData({
        item: e.product,
        quantityDigits: that.data.quantityDigits,
        priceDigits: that.data.priceDigits,
        isScanty: that.data.isScanty,
        spectStyle: that.data.spectStyle,
        areaCode: that.data.addr.code,
        addCompleted: function (goods) {
          that.onAddCartCompleted({
            detail: {
              product: goods,
              idx: e.idx,
              primaryKey: e.primaryKey
            }
          });
        }
      });
      that.fasterComponent.onShowGoodsModal(e);
    },
    /**
     * 加入完成后调用，更新界面显示数量
     */
    onAddCartCompleted(e) {
      var that = this;
      e = e.detail;
      that.data.widgets[e.primaryKey].Datas[e.idx] = e.product;
      that.setData({
        widgets: that.data.widgets
      });
    },
    /*
    弹出缺货登记的层 
    */
    showScantyModal(e) {
      var that = this;
      var idx = e.currentTarget.dataset.idx;
      var gidx = e.currentTarget.dataset.gidx;
      var product = that.data.widgets[idx].Datas[gidx]
      if (product.IsSingle == 0) {
        that.onShowGoodsModal({
          detail: {
            product: product,
            idx: idx
          }
        });
      } else {
        let unit_index = 0;
        for (let k = 0; k < product.AuxiliaryUnits.length; k++) {
          if (product.AuxiliaryUnits[k].Name == product.AuxUnit) {
            unit_index = k;
            break;
          }
        }
        product.ZIndex = unit_index;
        // console.log(product,'=========product');
        if (product.EnableSKUTranslated != 1) {
          let units = product.AuxiliaryUnits || [];
          product.productUnitText = detail.loadUnitContext(units, product.Unit);
        }
        that.outofstock.setData({
          scantyProduct: product,
        })
        that.outofstock.openScanyDialog(e);
      }
    },
    showStockDistribution(e) {
      var idx = e.currentTarget.dataset.idx;
      var gidx = e.currentTarget.dataset.gidx;
      var product = this.data.widgets[idx].Datas[gidx]
      this.stockdistribution.setData({
        product: product,
      })
      this.stockdistribution.showStockModal(e);
    },
    /**
     * 配送至弹层选择地址
     */
    selectedAdress(e) {
      this.setData({
        addr: {
          area: e.detail.Area,
          code: e.detail.Code
        }
      }, () => {
        this.loadPageWidgets(0);
      })
    },
    onNoticeParent(e) {
      this.triggerEvent('completeCallBack', {})
    },
    /**
     * 关闭分享弹层
     */
    shutShareShadow: function () {
      this.setData({
        showShareShadow: false
      })
    },
    /**
     * 跳转直播
     */
    goToLive: function (e) {
      var roomid = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: `plugin-private://wx2b03c6e691cd7370/pages/live-player-plugin?room_id=${roomid}`
      })
      requirePlugin('live-player-plugin').getLiveStatus({
          room_id: roomid
        })
        .then(res => {
          console.log(res, '====');
          // 101: 直播中, 102: 未开始, 103: 已结束, 104: 禁播, 105: 暂停中, 106: 异常，107：已过期 
          const liveStatus = res.liveStatus
          let data = {
            id: roomid,
            status: liveStatus
          }
          liveService.updateLiveStatus(data)
        })
        .catch(err => {
          console.log('get live status', err)
        })
    },
    /**
     * 获取已加载的内容区域高度
     */
    getContentHeight () {
      return new Promise((resolve) => {
        let query = this.createSelectorQuery()
        query.select('.tempMain').fields({
          size: true
        }).exec((res) => {
          console.log(res)
          if (res && res.length > 0) {
            if (res[0]) {
              resolve(res[0].height)
            } else {
              resolve(-1)
            }
          } else {
            resolve(-1)
          }
        })
      })
    },
    /**
     * 修改首页组件单项展示时的样式
     */
    renderItemStyle(widget = {}) {
      if (widget.WidgetName == 'Search') {
        // 搜索使用后台设置的高度
        widget.customStyle = `height:${widget.Height || 40}px;line-height:${widget.Height}px;`
      }
      if (widget.WidgetName == 'Navigation') {
        // 导航组件背景色和文字样式
        widget.backgroundStyle = `background-color: ${widget.BGColor || '#fff'};`
        widget.fontStyle = `color: ${widget.Color || '#666'};font-size: ${widget.FontSize || '14'}px;`
      }
      if (widget.WidgetName == 'Carousel') {
        // 轮播图标题文字样式
        widget.fontStyle = `color: ${widget.Color || '#666'};font-size: ${widget.FontSize || '14'}px;`
      }
      // 图片橱窗组件样式和图片组件样式
      if (widget.WidgetName == 'PictureSet' || widget.WidgetName == 'Picture') {
        widget.backgroundStyle = `background-color: ${widget.BGColor || '#fff'};`
        if (widget.BGSrc) {
          // 底图
          let src = api.imgDomain + widget.BGSrc
          widget.backgroundStyle += `background-image: url(${src});background-repeat: no-repeat;background-size: contain;background-position: center;`
        }
        widget.itemImgStyle = ''
        // 图片圆角
        if (widget.Border == 'radius') {
          widget.itemImgStyle += `border-radius: 10px;`
        }
        // 图片间隙
        if (widget.Style == 'hasborder' && widget.Margin) {
          if (widget.WidgetName == 'Picture') {
            widget.itemImgStyle += `padding: ${widget.Margin}px;box-sizing: border-box;`
          } else {
            widget.itemImgStyle += `top: ${widget.Margin}px;bottom: ${widget.Margin}px;left: ${widget.Margin}px;right: ${widget.Margin}px;`
          }
        }
        if (widget.WidgetName == 'PictureSet') {
          widget.itemImgStyle += 'text-align: center;display: flex;flex-direction: column;justify-content: center;'
        }
        // 标题文字样式
        widget.fontStyle = `color: ${widget.Color || '#303030'};font-size: ${widget.FontSize || '14'}px;`
      }
      // 商品组件
      if (widget.WidgetName == 'Products' || widget.WidgetName == 'ProductsCart') {
        widget.fontStyle = `color: ${widget.Color || '#666'};font-size: ${widget.FontSize || '14'}px;` // 标题
        widget.itemStyle = '' // 间距
        widget.contentStyle = `background-color: ${widget.BGColor || '#fff'};` // 背景色
        widget.picblockStyle = '' // 图片区域样式
        widget.imgStyle = {} // 图片样式
        if (widget.Border == 'radius') {
          // 圆角
          widget.contentStyle += `border-radius: 10px;`
        }
        if (widget.Margin) {
          widget.itemStyle += `padding: ${widget.Margin}px;`
        }
        if (widget.CssName == 'show-1') {
          if (widget.Position == 'scale-3-4') {
            widget.imgStyle = {
              width: 300,
              height: 400
            }
          }
        } else {
          if (widget.Position == 'scale-3-4') {
            widget.picblockStyle = `padding-top: 133.33%;`
            widget.imgStyle = {
              width: 300,
              height: 400
            }
          }
        }
      }
      // 特价、预售、拼团
      if (widget.WidgetName == "PanicBuy" || widget.WidgetName == "GroupBuy" || widget.WidgetName == "PreSale" || widget.WidgetName == 'PackedSale') {
        // 标题文字样式
        widget.fontStyle = `color: ${widget.Color || '#303030'};font-size: ${widget.FontSize || '14'}px;`
        widget.contentStyle = `background-color: ${widget.BGColor || '#fff'};` // 背景色
        if (widget.Border == 'radius') {
          // 圆角
          widget.contentStyle += `border-radius: 10px;`
        }
      }
      return widget
    },
  }
})